const Core = require('@alicloud/pop-core');

const client = new Core({
    accessKeyId: 'LTAI5tGuQznCD3PiJopKszf2',
    accessKeySecret: 'RkA94xQJeyabCb4jhXHr16yZ9Q8bJ9',
    // securityToken: '<your-sts-token>', // use STS Token
    endpoint: 'https://dysmsapi.aliyuncs.com',
    apiVersion: '2017-05-25'
});


async function sendSms(phoneNumbers, templateCode, templateParam) {

    return new Promise(function (resolve, reject) {

        let params = {
            "PhoneNumbers": phoneNumbers,
            "SignName": "爬宠拍拍",
            "TemplateCode": templateCode,
            "TemplateParam": JSON.stringify(templateParam)
        };

        let requestOption = {
            method: 'POST',
            formatParams: false,

        };

        client.request('SendSms', params, requestOption).then((result) => {
            resolve(result);
        }, (ex) => {
            reject(ex);
        })
    });
}


module.exports = {
    sendSms
};